/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.test.web;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jodd.bean.BeanTemplateParser;
import jodd.http.HttpRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.google.common.collect.Maps;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.test.entity.Test;

/**
 * jodd只能运行在JDK7或者更高的版本
 * @author duhongming
 * @version 2016-08-25
 */
@Controller
@RequestMapping(value = "${adminPath}/test/fnx")
public class joddController extends BaseController { 
	/**
	 * jodd http Http的get和post提交
	 * @param test
	 * @param request
	 * @param response
	 * @param model
	 */
	public void http(Test test, HttpServletRequest request, HttpServletResponse response, Model model) {
		
		//发送邮件数据到服务器端（post）
        HttpRequest.post("http://sendinfo.com.cn/email/sendMessage")
                    .form("data", "content")
                    .connectionKeepAlive(true)
                    .send();
        
        //发送邮件数据到服务器端（get）
        HttpRequest.get("http://sendinfo.com.cn/email/sendMessage")
                    .form("data", "content")
                    .connectionKeepAlive(true)
                    .send(); 
		
		
	}
	/**
	 * jodd string
	 * @param test
	 * @param request
	 * @param response
	 * @param model
	 */
	public void string(Test test, HttpServletRequest request, HttpServletResponse response, Model model) {
		//也可以是JavaBean
		Map<String,String> map = Maps.newHashMap();
		map.put("userName", "供应商联系人");
		map.put("mobile", "供应商联系人电话  ");
		map.put("joinDate", "注册时间");
		map.put("company", "公司名称");
	    // prepare template
		String qStr =" from BidderBean where ";
		qStr +=	" status = 'check' ";
		qStr += " and contacts like '%${userName}%' ";//供应商联系人 
		qStr += " and mobile like '%${mobile}%' ";//供应商联系人电话  
		qStr += " and joinDate >= '${joinDate}' ";//注册时间
		qStr += " and company like '%${company}%' ";//公司名称		      
		qStr += " order by joinDate desc ";
	    // parse
	    BeanTemplateParser btp = new BeanTemplateParser();
	    String result = btp.parse(qStr, map);
	    System.out.println("处理后的字符串:"+result);
	}

}
